#include <stdio.h>

#define BASE (10)


int main(int argc, const char ** argv)
{
	long num = 0;
	long reversed = 0;

	/*
	 * get input from user and validate 
	 */
	printf("Enter a number: ");
	scanf("%ld", &num);
	if (num < 0) {
		printf("Error! number must be >= 0\n");
		return -1;
	}

	/*
	 * reverse the digits of the input number 
	 * (the digit is num % 10)
	 */
	while (num > 0) {
		reversed *= BASE;
		reversed += num % BASE;
		num /= BASE;
	}
	printf("Reversed number: %ld\n", reversed);

	/* 
	 * great success 
	 */
	return 0;
}

